<template>
  <div>
    <el-dialog :title="change.show?'修改合作商':'新增合作商'" :visible="visible" @close="closeFn" width="40%" >
      <el-form class="from" label-position="right" label-width="25%" ref="Form"  :rules="rules" :model="bear">
        <el-form-item label="合作商名称:"  prop="name">
          <el-input v-model="bear.name"  maxlength="10" show-word-limit autocomplete="off" placeholder="请输入内容"  style="width:70%"></el-input>
        </el-form-item>
        <el-form-item label="联系人:"  prop="contact">
          <el-input v-model="bear.contact"  maxlength="10"  show-word-limit autocomplete="off" placeholder="请输入内容"  style="width:70%"></el-input>
        </el-form-item>
        <el-form-item label="联系电话:"  class="mobile" prop="mobile">
          <el-input v-model="bear.mobile" autocomplete="off" show-word-limit  maxlength="11" placeholder="请输入内容"  style="width:70%"></el-input>
        </el-form-item>
         <el-form-item label="分成比例(%):"   prop="ratio">
          <el-input-number v-model="bear.ratio" controls-position="right"  :min="1" :max="100" placeholder="请输入内容"  style="width:70%">
          </el-input-number>
           <span class="add"></span>
        </el-form-item>
      <template v-if="!this.change.show" >
        <el-form-item label="账号:"  prop="account">
          <el-input v-model="bear.account" autocomplete="off"  show-word-limit maxlength="18" placeholder="请输入内容"  style="width:70%"></el-input>
        </el-form-item>
        <el-form-item label="密码:"   prop="password">
          <el-input v-model="bear.password"  autocomplete="off"  show-word-limit maxlength="20" placeholder="请输入内容"  style="width:70%"></el-input>
        </el-form-item>
        </template>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeFn">取 消</el-button>
        <el-button type="primary" @click.native="abst">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { add, revise } from '@/api/getLevel/interIocal'
export default {
  watch: {
    change: {
      deep: true,
      handler () {
        if (this.change.show) {
          this.bear.id = this.change.id
          this.bear.name = this.change.name
          this.bear.ratio = this.change.ratio
          this.bear.contact = this.change.contact
          this.bear.mobile = this.change.mobile
          this.bear.phone = this.change.mobile
        }
      }
    }

  },
  data () {
    return {
      bear: {
        id: '',
        show: '',
        account: '',
        contact: '',
        mobile: '',
        name: '',
        password: '',
        ratio: '',
        phone: ''
      },
      rules: {
        name: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        contact: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        mobile: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        ratio: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        account: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        password: [{ required: true, message: '请输入活动名称', trigger: 'blur' }]
      }
    }
  },
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    change: {
      type: Object,
      required: true
    }
  },
  methods: {
    closeFn () {
      this.bear = {
        id: '',
        show: '',
        account: '',
        contact: '',
        mobile: '',
        name: '',
        password: '',
        ratio: '',
        phone: ''
      }
      this.$refs.Form.resetFields()
      this.$emit('update:visible', false)
    },
    async abst () {
      if (this.change.show) {
        const reg = await revise(this.bear)
        console.log(reg)
      } else {
        const res = await add(this.bear)
        console.log(res)
      } this.$emit('abst')
      this.closeFn()
    }
  }
}
</script>

<style lang="scss" scoped>
// .from{
//  margin-left: 5%;
//  .contact{
//   margin-left:  5.6%;
//  }
//  .mobile{
//   margin-left:  2.6%;
//  }
//  .account{
//   margin-left:  8.6%;
//  }
//  .ratio{

//  }
// }
.add{
  width: 100%;
  height: 5px;
}
</style>
